using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

public delegate void EventAction(params object[] messages);


public class EventHandle
{
    private Dictionary<string, EventAction> _eventDict = new Dictionary<string, EventAction>();

    public void AddListener(string eventName, EventAction action)
    {
        if (_eventDict.ContainsKey(eventName))
        {
            _eventDict[eventName] += action;
        }
        else
        {
            _eventDict.Add(eventName, action);
        }
    }

    public void RemoveListener(string eventName, EventAction action)
    {
        if (_eventDict.ContainsKey(eventName))
        {
            _eventDict[eventName] -= action;
        }
    }

    public void RemoveAllListeners(string eventName)
    {
        if (_eventDict.ContainsKey(eventName))
        {
            _eventDict.Remove(eventName);
        }
    }

    public void Invoke(string eventName, params object[] messages)
    {
        if (_eventDict.ContainsKey(eventName))
        {
            _eventDict[eventName](messages);
        }
    }

    public void Clear()
    {
        _eventDict.Clear();
    }
}
